package com.sfexpress.tools.entity;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;

import com.sfexpress.tools.utils.Pair;

public class ConsCheckResult {
	
	private boolean coincident = true;
	private ItemResult<MysqlTableInfo> tbInfoCheckResult;
	private ItemResult<MysqlColumnInfo> colInfoCheckResult;
	private ItemResult<MysqlTableConstInfo> tbConstCheckResult;
	private ItemResult<MysqlColumnConstInfo> colConstCheckResult;
	private ItemResult<MysqlIndexInfo> idxInfoCheckResult;
	
	public ConsCheckResult() {
		
		tbInfoCheckResult = new ItemResult<MysqlTableInfo>();
		colInfoCheckResult = new ItemResult<MysqlColumnInfo>();
		tbConstCheckResult = new ItemResult<MysqlTableConstInfo>();
		colConstCheckResult = new ItemResult<MysqlColumnConstInfo>();
		idxInfoCheckResult = new ItemResult<MysqlIndexInfo>();
		
	}

	public boolean isCoincident() {
		
		this.coincident = this.tbInfoCheckResult.isCoincident() 
							&& this.colInfoCheckResult.isCoincident()
							&& this.tbConstCheckResult.isCoincident()
							&& this.colConstCheckResult.isCoincident()
							&& this.idxInfoCheckResult.isCoincident();
		
		return coincident;
	}

	public void setCoincident(boolean isCoincident) {
		this.coincident = isCoincident;
	}
	
	public ItemResult<MysqlTableInfo> getTbInfoCheckResult() {
		return tbInfoCheckResult;
	}

	public void setTbInfoCheckResult(ItemResult<MysqlTableInfo> tbInfoCheckResult) {
		this.tbInfoCheckResult = tbInfoCheckResult;
	}

	public ItemResult<MysqlColumnInfo> getColInfoCheckResult() {
		return colInfoCheckResult;
	}

	public void setColInfoCheckResult(ItemResult<MysqlColumnInfo> colInfoCheckResult) {
		this.colInfoCheckResult = colInfoCheckResult;
	}

	public ItemResult<MysqlTableConstInfo> getTbConstCheckResult() {
		return tbConstCheckResult;
	}

	public void setTbConstCheckResult(ItemResult<MysqlTableConstInfo> tbConstCheckResult) {
		this.tbConstCheckResult = tbConstCheckResult;
	}

	public ItemResult<MysqlColumnConstInfo> getColConstCheckResult() {
		return colConstCheckResult;
	}

	public void setColConstCheckResult(ItemResult<MysqlColumnConstInfo> colConstCheckResult) {
		this.colConstCheckResult = colConstCheckResult;
	}

	public ItemResult<MysqlIndexInfo> getIdxInfoCheckResult() {
		return idxInfoCheckResult;
	}

	public void setIdxInfoCheckResult(ItemResult<MysqlIndexInfo> idxInfoCheckResult) {
		this.idxInfoCheckResult = idxInfoCheckResult;
	}
	
	public static class ConflictItem {
		
		private String key;
		private String item;
		private String firstItemContent;
		private String secondItemContent;
		
		public ConflictItem(String key, String item, String firstItemContent, String secondItemContent) {
			this.key = key;
			this.item = item;
			this.firstItemContent = firstItemContent;
			this.secondItemContent = secondItemContent;
		}
		
		public String getKey() {
			return key;
		}
		public void setKey(String key) {
			this.key = key;
		}
		public String getItem() {
			return item;
		}
		public void setItem(String item) {
			this.item = item;
		}
		public String getFirstItemContent() {
			return firstItemContent;
		}
		public void setFirstItemContent(String firstItemContent) {
			this.firstItemContent = firstItemContent;
		}
		public String getSecondItemContent() {
			return secondItemContent;
		}
		public void setSecondItemContent(String secondItemContent) {
			this.secondItemContent = secondItemContent;
		}
		
	}
	
	public static class ItemResult<E> {
		
		List<E> newItems;
		List<E> deletedItems;
		List<Pair<E, E>> conflictItems;
		
		Map<String, List<ConflictItem>> conflictItemMap;
		
		boolean coincident = true;
		
		public ItemResult() {
			newItems = new ArrayList<E>();
			deletedItems = new ArrayList<E>();
			conflictItems = new ArrayList<Pair<E, E>>();
			conflictItemMap = new TreeMap<String, List<ConflictItem>>();
		}
		
		public List<E> getNewItems() {
			return this.newItems;
		}
		
		public List<E> getDeletedItems() {
			return this.deletedItems;
		}
		
		public List<Pair<E, E>> getConflictItems() {
			return this.conflictItems;
		}

		public boolean isCoincident() {
			return coincident;
		}

		public void setCoincident(boolean coincident) {
			this.coincident = coincident;
		}
		
		public Map<String, List<ConflictItem>> getConflictItemMap() {
			return this.conflictItemMap;
		}
		
		public void addConflictItem(String key, ConflictItem item) {
			List<ConflictItem> values = this.conflictItemMap.get(key);
			if(values == null) {
				this.conflictItemMap.put(key, new ArrayList<ConsCheckResult.ConflictItem>());
				values =this.getConflictItemMap().get(key);
			}
			values.add(item);
		}
		
	}
	
}
